package com.demo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.module.commonui.R;

public class CustomInfoView extends LinearLayout {
    private LinearLayout linearLayout;
    private ImageView ivCustom;
    private TextView tvCustom;

    public LinearLayout getLinearLayout(){
        return linearLayout;
    }
    public CustomInfoView(Context context) {
        super(context);
        initContentView(context);
    }

    public CustomInfoView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomInfoView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initContentView(context);
    }

    public void initContentView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.customer_info, this);
        linearLayout = view.findViewById(R.id.ll_custom);
        ivCustom = view.findViewById(R.id.iv_customer);
        tvCustom = view.findViewById(R.id.tv_custom);
    }


    public void setCustomText(int count){
        if (count > 0){
            linearLayout.setBackgroundResource(R.drawable.white_customer_bg);
            ivCustom.setImageResource(R.drawable.tange_global_customer_red_service);
            tvCustom.setVisibility(VISIBLE);
            if (count < 10){
                tvCustom.setText("(" + count + ")");
            }else {
                tvCustom.setText("(9+)");
            }

        }else {
            linearLayout.setBackgroundResource(R.color.transparent);
            ivCustom.setImageResource(R.drawable.tange_global_customer_white_service);
            tvCustom.setVisibility(GONE);
        }
    }

    public void setListener(View.OnClickListener onClickListener){
        linearLayout.setOnClickListener(onClickListener);
        ivCustom.setOnClickListener(onClickListener);
        tvCustom.setOnClickListener(onClickListener);
    }
}